package exer;

/**
 * @author tongchen
 * @create 2023-01-17 17:24
 */
public class MyTask implements Comparable<MyTask>{
    private long time;
    private Runnable runnable;
//创建get任务和时间

    public long getTime() {
        return time;
    }

    public Runnable getRunnable() {
        return runnable;
    }
//创建构造方法
    public MyTask(Runnable runnable,long time){
        //判断时间的可靠性
        if(time<0){
            throw  new RuntimeException("时间错误");
        }
        this.time=time+System.currentTimeMillis();
        this.runnable=runnable;
    }
    @Override
    public int compareTo(MyTask o) {
        //第一种方式
      //  return this.time-o.time;
        //为了防止越界，我们选择第二种比较方式
        if(this.time>o.time){
            return 1;
        }
        if(this.time==o.time){
            return  0;
        }
        else{
            return -1;
        }
    }
}
